
// <copyright file="CultureHelper.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The culture helper.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Globalization
{
    using System.Configuration;
    using System.Globalization;
    using System.Threading;

    /// <summary>
    /// The culture helper.
    /// </summary>
    public static class CultureHelper
    {
        #region Public Properties

        /// <summary>
        /// Gets the culture name app settings key.
        /// </summary>
        public static string CultureNameAppSettingsKey
        {
            get
            {
                return "CultureName";
            }
        }

        /// <summary>
        /// Gets the default culture.
        /// </summary>
        public static string DefaultCulture
        {
            get
            {
                return "en-US";
            }
        }

        #endregion Public Properties

        #region Public Methods and Operators

        /// <summary>
        /// The set culture.
        /// </summary>
        public static void SetCulture()
        {
            string culture = ConfigurationManager.AppSettings[CultureNameAppSettingsKey];
            SetCulture(culture);
        }

        /// <summary>
        /// The set culture.
        /// </summary>
        /// <param name="culture">
        /// The culture.
        /// </param>
        public static void SetCulture(string culture)
        {
            SetCulture(culture, Thread.CurrentThread);
        }

        /// <summary>
        /// The set culture.
        /// </summary>
        /// <param name="thread">
        /// The thread.
        /// </param>
        public static void SetCulture(Thread thread)
        {
            string culture = ConfigurationManager.AppSettings[CultureNameAppSettingsKey];
            SetCulture(culture, Thread.CurrentThread);
        }

        /// <summary>
        /// The set culture.
        /// </summary>
        /// <param name="culture">
        /// The culture.
        /// </param>
        /// <param name="thread">
        /// The thread.
        /// </param>
        public static void SetCulture(string culture, Thread thread)
        {
            thread.CurrentCulture = thread.CurrentUICulture = new CultureInfo(string.IsNullOrEmpty(culture) ? DefaultCulture : culture);
        }

        #endregion Public Methods and Operators
    }
}
